﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace bleissem.CMWVS
{
    public class AddInTraceListener : TraceListener
    {
        #region Constructor

        private AddInTraceListener()
        {
        }

        public AddInTraceListener(Action<string> listen)
        {
            m_Listen = listen;
        }

        #endregion Constructor

        private Action<string> m_Listen;

        public override void Write(string message)
        {
            this.WriteLine(message + Environment.NewLine);
        }

        public override void WriteLine(string message)
        {
            if (string.IsNullOrWhiteSpace(message))
            {
                return;
            }
            if (!message.EndsWith(Environment.NewLine))
            {
                message += Environment.NewLine;
            }
            m_Listen(message);
        }

        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
            m_Listen = null;
        }
    }
}